THE BATTLE OF NEIGHBORHOODS

New York City's demographics show that it is a large and ethnically diverse metropolis. With it's diverse culture , comes diverse food items. There are many resturants in New york City, each beloning to different categories like Chinese , Indian , French etc.

So as part of this project , we will list and visualize all major parts of New York City that has great indian resturants.

Methodology:

  1. We begin by collecting the New York city data from "https://cocl.us/new_york_dataset".
  2. We will find all venues for each neighborhood using FourSquare API.
  3. We will then filter out all Indian Restuarant venues.
  4. Next using FourSquare API, we will find the Ratings, Tips, and Like count for all the Indian Resturants.
  5. Next we will sort the data keeping Ratings as the constraint.
  6. Finally, we will visualize the Ranking of neighborhoods using python's Folium library.
In [78]:
# required libraries

import pandas as pd
import numpy as np
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
import requests
from bs4 import BeautifulSoup
#!pip install geocoder
import geocoder
import os
!pip install folium
import folium # map rendering library
from geopy.geocoders import Nominatim # convert an address into latitude and longitude values
# Matplotlib and associated plotting modules
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as colors
%matplotlib inline
Requirement already satisfied: folium in k:\softwares\anaconda3\envs\tf\lib\site-packages (0.5.0)
Requirement already satisfied: branca in k:\softwares\anaconda3\envs\tf\lib\site-packages (from folium) (0.4.1)
Requirement already satisfied: jinja2 in k:\softwares\anaconda3\envs\tf\lib\site-packages (from folium) (2.11.2)
Requirement already satisfied: requests in k:\softwares\anaconda3\envs\tf\lib\site-packages (from folium) (2.23.0)
Requirement already satisfied: six in k:\softwares\anaconda3\envs\tf\lib\site-packages (from folium) (1.14.0)
Requirement already satisfied: MarkupSafe>=0.23 in k:\softwares\anaconda3\envs\tf\lib\site-packages (from jinja2->folium) (1.1.1)
Requirement already satisfied: chardet<4,>=3.0.2 in k:\softwares\anaconda3\envs\tf\lib\site-packages (from requests->folium) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in k:\softwares\anaconda3\envs\tf\lib\site-packages (from requests->folium) (2.9)
Requirement already satisfied: certifi>=2017.4.17 in k:\softwares\anaconda3\envs\tf\lib\site-packages (from requests->folium) (2020.11.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in k:\softwares\anaconda3\envs\tf\lib\site-packages (from requests->folium) (1.25.8)
In [79]:
# function to get the geocodes i.e latitude and longitude of a given location

def geo_location(address):
    # get geo location of address
    geolocator = Nominatim(user_agent="ny_explorer")
    location = geolocator.geocode(address)
    latitude = location.latitude
    longitude = location.longitude
    return latitude,longitude
In [184]:
# function to intract with FourSquare API and will return the venue id , venue name and category.

def get_venues(lat,lng):
    
    #set variables
    radius=1000
    LIMIT=100
    CLIENT_ID = '#'# Foursquare ID, note there is a daily call quota limit 
    CLIENT_SECRET ='#' # Foursquare Secret, note there is a daily call quota it
    VERSION = '20201118' # Foursquare API version
    
    #url to fetch data from foursquare api
    url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format(
            CLIENT_ID, 
            CLIENT_SECRET, 
            VERSION, 
            lat, 
            lng, 
            radius, 
            LIMIT)
    
    # get all the data
    results = requests.get(url).json()
    venue_data=results["response"]['groups'][0]['items']
    venue_details=[]
    for row in venue_data:
        try:
            venue_id=row['venue']['id']
            venue_name=row['venue']['name']
            venue_category=row['venue']['categories'][0]['name']
            venue_details.append([venue_id,venue_name,venue_category])
        except KeyError:
            pass
        
    column_names=['ID','Name','Category']
    df = pd.DataFrame(venue_details,columns=column_names)
    return df
In [193]:
# function to get venue details like like count , rating , tip counts for a given venue id. 

def get_venue_details(venue_id):
        
    CLIENT_ID = '#'# Foursquare ID, note there is a daily call quota limit 
    CLIENT_SECRET ='#' # Foursquare Secret, note there is a daily call quota it it
    VERSION = '20201118' # Foursquare API version
    
    #url to fetch data from foursquare api
    url = 'https://api.foursquare.com/v2/venues/{}?&client_id={}&client_secret={}&v={}'.format(
            venue_id,
            CLIENT_ID, 
            CLIENT_SECRET, 
            VERSION)
    
    # get all the data
    results = requests.get(url).json()
    venue_data=results['response']['venue']
    venue_details=[]
    try:
        venue_id=venue_data['id']
        venue_name=venue_data['name']
        venue_likes=venue_data['likes']['count']
        venue_rating=venue_data['rating']
        venue_tips=venue_data['tips']['count']
        venue_details.append([venue_id,venue_name,venue_likes,venue_rating,venue_tips])
    except KeyError:
        pass
        
    column_names=['ID','Name','Likes','Rating','Tips']
    df = pd.DataFrame(venue_details,columns=column_names)
    return df
In [82]:
# Funtion to get the new york city data such as Boroughs, Neighborhoods along with their latitude and longitude.

def get_new_york_data():
    url='https://cocl.us/new_york_dataset'
    resp=requests.get(url).json()
    # all data is present in features label
    features=resp['features']
    
    # define the dataframe columns
    column_names = ['Borough', 'Neighborhood', 'Latitude', 'Longitude'] 
    # instantiate the dataframe
    new_york_data = pd.DataFrame(columns=column_names)
    
    for data in features:
        borough = data['properties']['borough'] 
        neighborhood_name = data['properties']['name']
        
        neighborhood_latlon = data['geometry']['coordinates']
        neighborhood_lat = neighborhood_latlon[1]
        neighborhood_lon = neighborhood_latlon[0]
    
        new_york_data = new_york_data.append({'Borough': borough,
                                          'Neighborhood': neighborhood_name,
                                          'Latitude': neighborhood_lat,
                                          'Longitude': neighborhood_lon}, ignore_index=True)
    
    return new_york_data
In [83]:
new_york_data=get_new_york_data()
new_york_data.head()
new_york_data.shape
Out[83]:
(306, 4)

The above result shows that there are 306 different Neighborhoods in New York.

In [84]:
# create a BAR PLOT to show different Neighborhoods in New York

plt.figure(figsize=(9,5), dpi = 100)
# title
plt.title('Number of Neighborhood for each Borough in New York City')
#On x-axis
plt.xlabel('Borough', fontsize = 15)
#On y-axis
plt.ylabel('No.of Neighborhood', fontsize=15)
#giving a bar plot
new_york_data.groupby('Borough')['Neighborhood'].count().plot(kind='bar')
#legend
plt.legend()
#displays the plot
plt.show()

From the above Bar Plot, we can see that Queens has highest number of neighborhoods.

In [85]:
# prepare neighborhood list that contains indian resturants
column_names=['Borough', 'Neighborhood', 'ID','Name']
indian_rest_ny=pd.DataFrame(columns=column_names)
count=1
for row in new_york_data.values.tolist():
    Borough, Neighborhood, Latitude, Longitude=row
    venues = get_venues(Latitude,Longitude)
    indian_resturants=venues[venues['Category']=='Indian Restaurant']   
    print('(',count,'/',len(new_york_data),')','Indian Resturants in '+Neighborhood+', '+Borough+':'+str(len(indian_resturants)))
    for resturant_detail in indian_resturants.values.tolist():
        id, name , category=resturant_detail
        indian_rest_ny = indian_rest_ny.append({'Borough': Borough,
                                                'Neighborhood': Neighborhood, 
                                                'ID': id,
                                                'Name' : name
                                               }, ignore_index=True)
    count+=1
( 1 / 306 ) Indian Resturants in Wakefield, Bronx:0
( 2 / 306 ) Indian Resturants in Co-op City, Bronx:0
( 3 / 306 ) Indian Resturants in Eastchester, Bronx:0
( 4 / 306 ) Indian Resturants in Fieldston, Bronx:0
( 5 / 306 ) Indian Resturants in Riverdale, Bronx:0
( 6 / 306 ) Indian Resturants in Kingsbridge, Bronx:0
( 7 / 306 ) Indian Resturants in Marble Hill, Manhattan:0
( 8 / 306 ) Indian Resturants in Woodlawn, Bronx:1
( 9 / 306 ) Indian Resturants in Norwood, Bronx:0
( 10 / 306 ) Indian Resturants in Williamsbridge, Bronx:0
( 11 / 306 ) Indian Resturants in Baychester, Bronx:0
( 12 / 306 ) Indian Resturants in Pelham Parkway, Bronx:0
( 13 / 306 ) Indian Resturants in City Island, Bronx:0
( 14 / 306 ) Indian Resturants in Bedford Park, Bronx:0
( 15 / 306 ) Indian Resturants in University Heights, Bronx:0
( 16 / 306 ) Indian Resturants in Morris Heights, Bronx:0
( 17 / 306 ) Indian Resturants in Fordham, Bronx:0
( 18 / 306 ) Indian Resturants in East Tremont, Bronx:0
( 19 / 306 ) Indian Resturants in West Farms, Bronx:0
( 20 / 306 ) Indian Resturants in High  Bridge, Bronx:0
( 21 / 306 ) Indian Resturants in Melrose, Bronx:0
( 22 / 306 ) Indian Resturants in Mott Haven, Bronx:0
( 23 / 306 ) Indian Resturants in Port Morris, Bronx:0
( 24 / 306 ) Indian Resturants in Longwood, Bronx:0
( 25 / 306 ) Indian Resturants in Hunts Point, Bronx:0
( 26 / 306 ) Indian Resturants in Morrisania, Bronx:0
( 27 / 306 ) Indian Resturants in Soundview, Bronx:0
( 28 / 306 ) Indian Resturants in Clason Point, Bronx:0
( 29 / 306 ) Indian Resturants in Throgs Neck, Bronx:0
( 30 / 306 ) Indian Resturants in Country Club, Bronx:0
( 31 / 306 ) Indian Resturants in Parkchester, Bronx:1
( 32 / 306 ) Indian Resturants in Westchester Square, Bronx:0
( 33 / 306 ) Indian Resturants in Van Nest, Bronx:0
( 34 / 306 ) Indian Resturants in Morris Park, Bronx:0
( 35 / 306 ) Indian Resturants in Belmont, Bronx:0
( 36 / 306 ) Indian Resturants in Spuyten Duyvil, Bronx:1
( 37 / 306 ) Indian Resturants in North Riverdale, Bronx:0
( 38 / 306 ) Indian Resturants in Pelham Bay, Bronx:0
( 39 / 306 ) Indian Resturants in Schuylerville, Bronx:0
( 40 / 306 ) Indian Resturants in Edgewater Park, Bronx:0
( 41 / 306 ) Indian Resturants in Castle Hill, Bronx:0
( 42 / 306 ) Indian Resturants in Olinville, Bronx:0
( 43 / 306 ) Indian Resturants in Pelham Gardens, Bronx:0
( 44 / 306 ) Indian Resturants in Concourse, Bronx:1
( 45 / 306 ) Indian Resturants in Unionport, Bronx:1
( 46 / 306 ) Indian Resturants in Edenwald, Bronx:0
( 47 / 306 ) Indian Resturants in Bay Ridge, Brooklyn:2
( 48 / 306 ) Indian Resturants in Bensonhurst, Brooklyn:0
( 49 / 306 ) Indian Resturants in Sunset Park, Brooklyn:0
( 50 / 306 ) Indian Resturants in Greenpoint, Brooklyn:0
( 51 / 306 ) Indian Resturants in Gravesend, Brooklyn:0
( 52 / 306 ) Indian Resturants in Brighton Beach, Brooklyn:1
( 53 / 306 ) Indian Resturants in Sheepshead Bay, Brooklyn:0
( 54 / 306 ) Indian Resturants in Manhattan Terrace, Brooklyn:0
( 55 / 306 ) Indian Resturants in Flatbush, Brooklyn:2
( 56 / 306 ) Indian Resturants in Crown Heights, Brooklyn:0
( 57 / 306 ) Indian Resturants in East Flatbush, Brooklyn:1
( 58 / 306 ) Indian Resturants in Kensington, Brooklyn:2
( 59 / 306 ) Indian Resturants in Windsor Terrace, Brooklyn:0
( 60 / 306 ) Indian Resturants in Prospect Heights, Brooklyn:0
( 61 / 306 ) Indian Resturants in Brownsville, Brooklyn:0
( 62 / 306 ) Indian Resturants in Williamsburg, Brooklyn:0
( 63 / 306 ) Indian Resturants in Bushwick, Brooklyn:0
( 64 / 306 ) Indian Resturants in Bedford Stuyvesant, Brooklyn:0
( 65 / 306 ) Indian Resturants in Brooklyn Heights, Brooklyn:0
( 66 / 306 ) Indian Resturants in Cobble Hill, Brooklyn:0
( 67 / 306 ) Indian Resturants in Carroll Gardens, Brooklyn:0
( 68 / 306 ) Indian Resturants in Red Hook, Brooklyn:0
( 69 / 306 ) Indian Resturants in Gowanus, Brooklyn:1
( 70 / 306 ) Indian Resturants in Fort Greene, Brooklyn:1
( 71 / 306 ) Indian Resturants in Park Slope, Brooklyn:0
( 72 / 306 ) Indian Resturants in Cypress Hills, Brooklyn:0
( 73 / 306 ) Indian Resturants in East New York, Brooklyn:0
( 74 / 306 ) Indian Resturants in Starrett City, Brooklyn:0
( 75 / 306 ) Indian Resturants in Canarsie, Brooklyn:0
( 76 / 306 ) Indian Resturants in Flatlands, Brooklyn:0
( 77 / 306 ) Indian Resturants in Mill Island, Brooklyn:0
( 78 / 306 ) Indian Resturants in Manhattan Beach, Brooklyn:0
( 79 / 306 ) Indian Resturants in Coney Island, Brooklyn:0
( 80 / 306 ) Indian Resturants in Bath Beach, Brooklyn:0
( 81 / 306 ) Indian Resturants in Borough Park, Brooklyn:0
( 82 / 306 ) Indian Resturants in Dyker Heights, Brooklyn:0
( 83 / 306 ) Indian Resturants in Gerritsen Beach, Brooklyn:0
( 84 / 306 ) Indian Resturants in Marine Park, Brooklyn:0
( 85 / 306 ) Indian Resturants in Clinton Hill, Brooklyn:2
( 86 / 306 ) Indian Resturants in Sea Gate, Brooklyn:0
( 87 / 306 ) Indian Resturants in Downtown, Brooklyn:0
( 88 / 306 ) Indian Resturants in Boerum Hill, Brooklyn:0
( 89 / 306 ) Indian Resturants in Prospect Lefferts Gardens, Brooklyn:1
( 90 / 306 ) Indian Resturants in Ocean Hill, Brooklyn:2
( 91 / 306 ) Indian Resturants in City Line, Brooklyn:0
( 92 / 306 ) Indian Resturants in Bergen Beach, Brooklyn:0
( 93 / 306 ) Indian Resturants in Midwood, Brooklyn:0
( 94 / 306 ) Indian Resturants in Prospect Park South, Brooklyn:2
( 95 / 306 ) Indian Resturants in Georgetown, Brooklyn:0
( 96 / 306 ) Indian Resturants in East Williamsburg, Brooklyn:0
( 97 / 306 ) Indian Resturants in North Side, Brooklyn:1
( 98 / 306 ) Indian Resturants in South Side, Brooklyn:1
( 99 / 306 ) Indian Resturants in Ocean Parkway, Brooklyn:0
( 100 / 306 ) Indian Resturants in Fort Hamilton, Brooklyn:1
( 101 / 306 ) Indian Resturants in Chinatown, Manhattan:0
( 102 / 306 ) Indian Resturants in Washington Heights, Manhattan:1
( 103 / 306 ) Indian Resturants in Inwood, Manhattan:0
( 104 / 306 ) Indian Resturants in Hamilton Heights, Manhattan:2
( 105 / 306 ) Indian Resturants in Manhattanville, Manhattan:2
( 106 / 306 ) Indian Resturants in Central Harlem, Manhattan:2
( 107 / 306 ) Indian Resturants in East Harlem, Manhattan:1
( 108 / 306 ) Indian Resturants in Upper East Side, Manhattan:0
( 109 / 306 ) Indian Resturants in Yorkville, Manhattan:3
( 110 / 306 ) Indian Resturants in Lenox Hill, Manhattan:0
( 111 / 306 ) Indian Resturants in Roosevelt Island, Manhattan:1
( 112 / 306 ) Indian Resturants in Upper West Side, Manhattan:2
( 113 / 306 ) Indian Resturants in Lincoln Square, Manhattan:0
( 114 / 306 ) Indian Resturants in Clinton, Manhattan:0
( 115 / 306 ) Indian Resturants in Midtown, Manhattan:0
( 116 / 306 ) Indian Resturants in Murray Hill, Manhattan:0
( 117 / 306 ) Indian Resturants in Chelsea, Manhattan:1
( 118 / 306 ) Indian Resturants in Greenwich Village, Manhattan:1
( 119 / 306 ) Indian Resturants in East Village, Manhattan:0
( 120 / 306 ) Indian Resturants in Lower East Side, Manhattan:0
( 121 / 306 ) Indian Resturants in Tribeca, Manhattan:1
( 122 / 306 ) Indian Resturants in Little Italy, Manhattan:0
( 123 / 306 ) Indian Resturants in Soho, Manhattan:0
( 124 / 306 ) Indian Resturants in West Village, Manhattan:2
( 125 / 306 ) Indian Resturants in Manhattan Valley, Manhattan:2
( 126 / 306 ) Indian Resturants in Morningside Heights, Manhattan:1
( 127 / 306 ) Indian Resturants in Gramercy, Manhattan:5
( 128 / 306 ) Indian Resturants in Battery Park City, Manhattan:0
( 129 / 306 ) Indian Resturants in Financial District, Manhattan:0
( 130 / 306 ) Indian Resturants in Astoria, Queens:2
( 131 / 306 ) Indian Resturants in Woodside, Queens:8
( 132 / 306 ) Indian Resturants in Jackson Heights, Queens:5
( 133 / 306 ) Indian Resturants in Elmhurst, Queens:2
( 134 / 306 ) Indian Resturants in Howard Beach, Queens:0
( 135 / 306 ) Indian Resturants in Corona, Queens:0
( 136 / 306 ) Indian Resturants in Forest Hills, Queens:0
( 137 / 306 ) Indian Resturants in Kew Gardens, Queens:2
( 138 / 306 ) Indian Resturants in Richmond Hill, Queens:8
( 139 / 306 ) Indian Resturants in Flushing, Queens:0
( 140 / 306 ) Indian Resturants in Long Island City, Queens:2
( 141 / 306 ) Indian Resturants in Sunnyside, Queens:1
( 142 / 306 ) Indian Resturants in East Elmhurst, Queens:0
( 143 / 306 ) Indian Resturants in Maspeth, Queens:0
( 144 / 306 ) Indian Resturants in Ridgewood, Queens:1
( 145 / 306 ) Indian Resturants in Glendale, Queens:0
( 146 / 306 ) Indian Resturants in Rego Park, Queens:1
( 147 / 306 ) Indian Resturants in Woodhaven, Queens:0
( 148 / 306 ) Indian Resturants in Ozone Park, Queens:0
( 149 / 306 ) Indian Resturants in South Ozone Park, Queens:1
( 150 / 306 ) Indian Resturants in College Point, Queens:0
( 151 / 306 ) Indian Resturants in Whitestone, Queens:0
( 152 / 306 ) Indian Resturants in Bayside, Queens:3
( 153 / 306 ) Indian Resturants in Auburndale, Queens:0
( 154 / 306 ) Indian Resturants in Little Neck, Queens:0
( 155 / 306 ) Indian Resturants in Douglaston, Queens:0
( 156 / 306 ) Indian Resturants in Glen Oaks, Queens:4
( 157 / 306 ) Indian Resturants in Bellerose, Queens:0
( 158 / 306 ) Indian Resturants in Kew Gardens Hills, Queens:1
( 159 / 306 ) Indian Resturants in Fresh Meadows, Queens:0
( 160 / 306 ) Indian Resturants in Briarwood, Queens:3
( 161 / 306 ) Indian Resturants in Jamaica Center, Queens:4
( 162 / 306 ) Indian Resturants in Oakland Gardens, Queens:0
( 163 / 306 ) Indian Resturants in Queens Village, Queens:0
( 164 / 306 ) Indian Resturants in Hollis, Queens:0
( 165 / 306 ) Indian Resturants in South Jamaica, Queens:0
( 166 / 306 ) Indian Resturants in St. Albans, Queens:0
( 167 / 306 ) Indian Resturants in Rochdale, Queens:0
( 168 / 306 ) Indian Resturants in Springfield Gardens, Queens:0
( 169 / 306 ) Indian Resturants in Cambria Heights, Queens:0
( 170 / 306 ) Indian Resturants in Rosedale, Queens:0
( 171 / 306 ) Indian Resturants in Far Rockaway, Queens:0
( 172 / 306 ) Indian Resturants in Broad Channel, Queens:0
( 173 / 306 ) Indian Resturants in Breezy Point, Queens:0
( 174 / 306 ) Indian Resturants in Steinway, Queens:1
( 175 / 306 ) Indian Resturants in Beechhurst, Queens:0
( 176 / 306 ) Indian Resturants in Bay Terrace, Queens:0
( 177 / 306 ) Indian Resturants in Edgemere, Queens:0
( 178 / 306 ) Indian Resturants in Arverne, Queens:0
( 179 / 306 ) Indian Resturants in Rockaway Beach, Queens:0
( 180 / 306 ) Indian Resturants in Neponsit, Queens:0
( 181 / 306 ) Indian Resturants in Murray Hill, Queens:0
( 182 / 306 ) Indian Resturants in Floral Park, Queens:8
( 183 / 306 ) Indian Resturants in Holliswood, Queens:1
( 184 / 306 ) Indian Resturants in Jamaica Estates, Queens:2
( 185 / 306 ) Indian Resturants in Queensboro Hill, Queens:1
( 186 / 306 ) Indian Resturants in Hillcrest, Queens:0
( 187 / 306 ) Indian Resturants in Ravenswood, Queens:1
( 188 / 306 ) Indian Resturants in Lindenwood, Queens:0
( 189 / 306 ) Indian Resturants in Laurelton, Queens:0
( 190 / 306 ) Indian Resturants in Lefrak City, Queens:0
( 191 / 306 ) Indian Resturants in Belle Harbor, Queens:0
( 192 / 306 ) Indian Resturants in Rockaway Park, Queens:0
( 193 / 306 ) Indian Resturants in Somerville, Queens:0
( 194 / 306 ) Indian Resturants in Brookville, Queens:0
( 195 / 306 ) Indian Resturants in Bellaire, Queens:1
( 196 / 306 ) Indian Resturants in North Corona, Queens:0
( 197 / 306 ) Indian Resturants in Forest Hills Gardens, Queens:0
( 198 / 306 ) Indian Resturants in St. George, Staten Island:0
( 199 / 306 ) Indian Resturants in New Brighton, Staten Island:1
( 200 / 306 ) Indian Resturants in Stapleton, Staten Island:0
( 201 / 306 ) Indian Resturants in Rosebank, Staten Island:0
( 202 / 306 ) Indian Resturants in West Brighton, Staten Island:0
( 203 / 306 ) Indian Resturants in Grymes Hill, Staten Island:0
( 204 / 306 ) Indian Resturants in Todt Hill, Staten Island:0
( 205 / 306 ) Indian Resturants in South Beach, Staten Island:0
( 206 / 306 ) Indian Resturants in Port Richmond, Staten Island:0
( 207 / 306 ) Indian Resturants in Mariner's Harbor, Staten Island:0
( 208 / 306 ) Indian Resturants in Port Ivory, Staten Island:0
( 209 / 306 ) Indian Resturants in Castleton Corners, Staten Island:0
( 210 / 306 ) Indian Resturants in New Springville, Staten Island:0
( 211 / 306 ) Indian Resturants in Travis, Staten Island:0
( 212 / 306 ) Indian Resturants in New Dorp, Staten Island:1
( 213 / 306 ) Indian Resturants in Oakwood, Staten Island:0
( 214 / 306 ) Indian Resturants in Great Kills, Staten Island:0
( 215 / 306 ) Indian Resturants in Eltingville, Staten Island:0
( 216 / 306 ) Indian Resturants in Annadale, Staten Island:0
( 217 / 306 ) Indian Resturants in Woodrow, Staten Island:0
( 218 / 306 ) Indian Resturants in Tottenville, Staten Island:0
( 219 / 306 ) Indian Resturants in Tompkinsville, Staten Island:1
( 220 / 306 ) Indian Resturants in Silver Lake, Staten Island:0
( 221 / 306 ) Indian Resturants in Sunnyside, Staten Island:0
( 222 / 306 ) Indian Resturants in Ditmas Park, Brooklyn:2
( 223 / 306 ) Indian Resturants in Wingate, Brooklyn:0
( 224 / 306 ) Indian Resturants in Rugby, Brooklyn:0
( 225 / 306 ) Indian Resturants in Park Hill, Staten Island:1
( 226 / 306 ) Indian Resturants in Westerleigh, Staten Island:0
( 227 / 306 ) Indian Resturants in Graniteville, Staten Island:0
( 228 / 306 ) Indian Resturants in Arlington, Staten Island:0
( 229 / 306 ) Indian Resturants in Arrochar, Staten Island:0
( 230 / 306 ) Indian Resturants in Grasmere, Staten Island:0
( 231 / 306 ) Indian Resturants in Old Town, Staten Island:0
( 232 / 306 ) Indian Resturants in Dongan Hills, Staten Island:0
( 233 / 306 ) Indian Resturants in Midland Beach, Staten Island:0
( 234 / 306 ) Indian Resturants in Grant City, Staten Island:1
( 235 / 306 ) Indian Resturants in New Dorp Beach, Staten Island:0
( 236 / 306 ) Indian Resturants in Bay Terrace, Staten Island:0
( 237 / 306 ) Indian Resturants in Huguenot, Staten Island:0
( 238 / 306 ) Indian Resturants in Pleasant Plains, Staten Island:0
( 239 / 306 ) Indian Resturants in Butler Manor, Staten Island:0
( 240 / 306 ) Indian Resturants in Charleston, Staten Island:0
( 241 / 306 ) Indian Resturants in Rossville, Staten Island:0
( 242 / 306 ) Indian Resturants in Arden Heights, Staten Island:0
( 243 / 306 ) Indian Resturants in Greenridge, Staten Island:0
( 244 / 306 ) Indian Resturants in Heartland Village, Staten Island:0
( 245 / 306 ) Indian Resturants in Chelsea, Staten Island:0
( 246 / 306 ) Indian Resturants in Bloomfield, Staten Island:0
( 247 / 306 ) Indian Resturants in Bulls Head, Staten Island:0
( 248 / 306 ) Indian Resturants in Carnegie Hill, Manhattan:3
( 249 / 306 ) Indian Resturants in Noho, Manhattan:0
( 250 / 306 ) Indian Resturants in Civic Center, Manhattan:1
( 251 / 306 ) Indian Resturants in Midtown South, Manhattan:0
( 252 / 306 ) Indian Resturants in Richmond Town, Staten Island:0
( 253 / 306 ) Indian Resturants in Shore Acres, Staten Island:0
( 254 / 306 ) Indian Resturants in Clifton, Staten Island:0
( 255 / 306 ) Indian Resturants in Concord, Staten Island:0
( 256 / 306 ) Indian Resturants in Emerson Hill, Staten Island:0
( 257 / 306 ) Indian Resturants in Randall Manor, Staten Island:0
( 258 / 306 ) Indian Resturants in Howland Hook, Staten Island:0
( 259 / 306 ) Indian Resturants in Elm Park, Staten Island:0
( 260 / 306 ) Indian Resturants in Remsen Village, Brooklyn:0
( 261 / 306 ) Indian Resturants in New Lots, Brooklyn:0
( 262 / 306 ) Indian Resturants in Paerdegat Basin, Brooklyn:0
( 263 / 306 ) Indian Resturants in Mill Basin, Brooklyn:0
( 264 / 306 ) Indian Resturants in Jamaica Hills, Queens:4
( 265 / 306 ) Indian Resturants in Utopia, Queens:0
( 266 / 306 ) Indian Resturants in Pomonok, Queens:0
( 267 / 306 ) Indian Resturants in Astoria Heights, Queens:1
( 268 / 306 ) Indian Resturants in Claremont Village, Bronx:0
( 269 / 306 ) Indian Resturants in Concourse Village, Bronx:1
( 270 / 306 ) Indian Resturants in Mount Eden, Bronx:0
( 271 / 306 ) Indian Resturants in Mount Hope, Bronx:0
( 272 / 306 ) Indian Resturants in Sutton Place, Manhattan:3
( 273 / 306 ) Indian Resturants in Hunters Point, Queens:0
( 274 / 306 ) Indian Resturants in Turtle Bay, Manhattan:1
( 275 / 306 ) Indian Resturants in Tudor City, Manhattan:0
( 276 / 306 ) Indian Resturants in Stuyvesant Town, Manhattan:0
( 277 / 306 ) Indian Resturants in Flatiron, Manhattan:0
( 278 / 306 ) Indian Resturants in Sunnyside Gardens, Queens:1
( 279 / 306 ) Indian Resturants in Blissville, Queens:1
( 280 / 306 ) Indian Resturants in Fulton Ferry, Brooklyn:0
( 281 / 306 ) Indian Resturants in Vinegar Hill, Brooklyn:0
( 282 / 306 ) Indian Resturants in Weeksville, Brooklyn:0
( 283 / 306 ) Indian Resturants in Broadway Junction, Brooklyn:1
( 284 / 306 ) Indian Resturants in Dumbo, Brooklyn:0
( 285 / 306 ) Indian Resturants in Manor Heights, Staten Island:0
( 286 / 306 ) Indian Resturants in Willowbrook, Staten Island:0
( 287 / 306 ) Indian Resturants in Sandy Ground, Staten Island:0
( 288 / 306 ) Indian Resturants in Egbertville, Staten Island:0
( 289 / 306 ) Indian Resturants in Roxbury, Queens:0
( 290 / 306 ) Indian Resturants in Homecrest, Brooklyn:0
( 291 / 306 ) Indian Resturants in Middle Village, Queens:0
( 292 / 306 ) Indian Resturants in Prince's Bay, Staten Island:0
( 293 / 306 ) Indian Resturants in Lighthouse Hill, Staten Island:0
( 294 / 306 ) Indian Resturants in Richmond Valley, Staten Island:0
( 295 / 306 ) Indian Resturants in Malba, Queens:0
( 296 / 306 ) Indian Resturants in Highland Park, Brooklyn:0
( 297 / 306 ) Indian Resturants in Madison, Brooklyn:0
( 298 / 306 ) Indian Resturants in Bronxdale, Bronx:0
( 299 / 306 ) Indian Resturants in Allerton, Bronx:0
( 300 / 306 ) Indian Resturants in Kingsbridge Heights, Bronx:0
( 301 / 306 ) Indian Resturants in Erasmus, Brooklyn:1
( 302 / 306 ) Indian Resturants in Hudson Yards, Manhattan:0
( 303 / 306 ) Indian Resturants in Hammels, Queens:0
( 304 / 306 ) Indian Resturants in Bayswater, Queens:0
( 305 / 306 ) Indian Resturants in Queensbridge, Queens:2
( 306 / 306 ) Indian Resturants in Fox Hills, Staten Island:1
In [86]:
indian_rest_ny.head()

indian_rest_ny.shape
Out[86]:
(143, 4)

From the above result, we see that there are 143 Indian Resturants across New York City.

In [87]:
# BAR PLOT to show Number of Indian Resturants for each Borough in New York City.

plt.figure(figsize=(9,5), dpi = 100)
# title
plt.title('Number of Indian Resturants for each Borough in New York City')
#On x-axis
plt.xlabel('Borough', fontsize = 15)
#On y-axis
plt.ylabel('No.of Indian Resturants', fontsize=15)
#giving a bar plot
indian_rest_ny.groupby('Borough')['ID'].count().plot(kind='bar')
#legend
plt.legend()
#displays the plot
plt.show()

From the above Bar Plot, we can see that Queens has highest number of Indian resturants.

In [88]:
plt.figure(figsize=(9,5), dpi = 100)
# title
plt.title('Number of Indian Resturants for each Neighborhood in New York City')
#On x-axis
plt.xlabel('Neighborhood', fontsize = 15)
#On y-axis
plt.ylabel('No.of Indian Resturants', fontsize=15)
#giving a bar plot
indian_rest_ny.groupby('Neighborhood')['ID'].count().nlargest(5).plot(kind='bar')
#legend
plt.legend()
#displays the plot
plt.show()
In [187]:
indian_rest_ny[indian_rest_ny['Neighborhood']=='Floral Park']
Out[187]:
Borough Neighborhood ID Name
101 Queens Floral Park 527ffc0811d2d329d5e49abd Jackson Diner
102 Queens Floral Park 4e4e3e22bd4101d0d7a5c2d1 Kerala Kitchen
103 Queens Floral Park 4b647b56f964a520c4b62ae3 Usha Foods & Usha Sweets
104 Queens Floral Park 4b787c49f964a5209cd12ee3 Santoor Indian Restaurant
105 Queens Floral Park 4c0c01e0bbc676b00d6b4cd5 Mumbai Xpress
106 Queens Floral Park 4df0f39dd4c04d0392c853ea Sagar Chinese
107 Queens Floral Park 4c76ff35a5676dcb72671721 Flavor Of India
108 Queens Floral Park 4e6bfe1c7d8b2c711b17bbe5 Surya sweets and snacks

We can see that, Floral Park in Queens has the highest number of Indian Resturants with a total count of 8

In [ ]:
# get the  prepare neighborhood list that contains indian resturants

column_names=['Borough', 'Neighborhood', 'ID','Name','Likes','Rating','Tips']
indian_rest_stats_ny=pd.DataFrame(columns=column_names)
#print(indian_rest_ny.values[:50])
count=1


for row in indian_rest_ny.values.tolist():
    Borough,Neighborhood,ID,Name=row
    try:
        venue_details=get_venue_details(ID)
        print(venue_details)
        id,name,likes,rating,tips=venue_details.values.tolist()[0]
    except IndexError:
        print('No data available for id=',ID)
        # we will assign 0 value for these resturants as they may have been 
        #recently opened or details does not exist in FourSquare Database
        id,name,likes,rating,tips=[0]*5
    print('(',count,'/',len(indian_rest_ny),')','processed')
    indian_rest_stats_ny = indian_rest_stats_ny.append({'Borough': Borough,
                                                'Neighborhood': Neighborhood, 
                                                'ID': id,
                                                'Name' : name,
                                                'Likes' : likes,
                                                'Rating' : rating,
                                                'Tips' : tips
                                               }, ignore_index=True)
    count+=1 #ranking of each resturant for further analysis.
In [212]:
indian_rest_stats_ny.head()
Out[212]:
Borough Neighborhood ID Name Likes Rating Tips
0 Bronx Woodlawn 4c0448d9310fc9b6bf1dc761 Curry Spot 5.0 7.9 10.0
1 Bronx Parkchester 4c194631838020a13e78e561 Melanies Roti Bar And Grill 3.0 6.2 2.0
2 Bronx Spuyten Duyvil 4c04544df423a593ac83d116 Cumin Indian Cuisine 13.0 5.8 9.0
3 Bronx Concourse 551b7f75498e86c00a0ed2e1 Hungry Bird 8.0 7.2 3.0
4 Bronx Unionport 4c194631838020a13e78e561 Melanies Roti Bar And Grill 3.0 6.2 2.0
In [214]:
indian_rest_ny.shape
Out[214]:
(143, 4)
In [196]:
# saving to csv

indian_rest_stats_ny.to_csv('indian_rest_stats_ny.csv', index=False)
In [197]:
# loading data from csv

indian_rest_stats_ny_csv=pd.read_csv('indian_rest_stats_ny.csv')
indian_rest_stats_ny_csv.shape
indian_rest_stats_ny_csv.head()
Out[197]:
Borough Neighborhood ID Name Likes Rating Tips
0 Bronx Woodlawn 4c0448d9310fc9b6bf1dc761 Curry Spot 5 7.9 10
1 Bronx Parkchester 4c194631838020a13e78e561 Melanies Roti Bar And Grill 3 6.2 2
2 Bronx Spuyten Duyvil 4c04544df423a593ac83d116 Cumin Indian Cuisine 13 5.8 9
3 Bronx Concourse 551b7f75498e86c00a0ed2e1 Hungry Bird 8 7.2 3
4 Bronx Unionport 4c194631838020a13e78e561 Melanies Roti Bar And Grill 3 6.2 2
In [198]:
indian_rest_stats_ny['Likes']=indian_rest_stats_ny['Likes'].astype('float64')
indian_rest_stats_ny['Tips']=indian_rest_stats_ny['Tips'].astype('float64')

Indian restuarants with Maximum Likes, Maximum Ratings and Maximum Tips.

In [199]:
# Resturant with maximum Likes
indian_rest_stats_ny.iloc[indian_rest_stats_ny['Likes'].idxmax()]
Out[199]:
Borough                        Manhattan
Neighborhood                     Tribeca
ID              4bbb9dbded7776b0e1ad3e51
Name                    Tamarind TriBeCa
Likes                                600
Rating                               9.1
Tips                                 150
Name: 41, dtype: object
In [200]:
# Resturant with maximum Rating
indian_rest_stats_ny.iloc[indian_rest_stats_ny['Rating'].idxmax()]
Out[200]:
Borough                        Manhattan
Neighborhood           Greenwich Village
ID              5b5a2c9e66f3cd002ca0aab5
Name                      Bombay Bistros
Likes                                 31
Rating                               9.1
Tips                                   6
Name: 40, dtype: object
In [201]:
# Resturant with maximum Tips
indian_rest_stats_ny.iloc[indian_rest_stats_ny['Tips'].idxmax()]
Out[201]:
Borough                        Manhattan
Neighborhood                    Gramercy
ID              4a70a75bf964a52016d81fe3
Name                 Bhatti Indian Grill
Likes                                424
Rating                               8.7
Tips                                 162
Name: 47, dtype: object

visualize neighborhood with maximum average rating of resturants.

In [202]:
ny_neighborhood_stats=indian_rest_stats_ny.groupby('Neighborhood',as_index=False).mean()[['Neighborhood','Rating']]
ny_neighborhood_stats.columns=['Neighborhood','Average Rating']
In [203]:
ny_neighborhood_stats.sort_values(['Average Rating'],ascending=False).head(10)
Out[203]:
Neighborhood Average Rating
27 Tribeca 9.1
13 Greenwich Village 9.1
31 West Village 9.0
3 Chelsea 8.8
12 Gramercy 8.7
22 Prospect Lefferts Gardens 8.7
29 Upper West Side 8.6
9 Fort Greene 8.5
24 Roosevelt Island 8.4
25 South Side 8.3

Above are the top neighborhoods with top average rating of Indian resturants.

we will find the average rating of Indian Resturants for each Borough.

In [215]:
ny_borough_stats=indian_rest_stats_ny.groupby('Borough',as_index=False).mean()[['Borough','Rating']]
ny_borough_stats.columns=['Borough','Average Rating']

ny_borough_stats.sort_values(['Average Rating'],ascending=False).head()
Out[215]:
Borough Average Rating
2 Manhattan 8.356
1 Brooklyn 7.755
0 Bronx 6.660
In [205]:
# visualization

plt.figure(figsize=(9,5), dpi = 100)
# title
plt.title('Average rating of Indian Resturants for each Borough')
#On x-axis
plt.xlabel('Borough', fontsize = 15)
#On y-axis
plt.ylabel('Average Rating', fontsize=15)
#giving a bar plot
indian_rest_stats_ny.groupby('Borough').mean()['Rating'].plot(kind='bar')
#legend
plt.legend()
#displays the plot
plt.show()

consider all the neighborhoods with average rating greater or equal 9.0 to visualize on map.m

In [206]:
ny_neighborhood_stats=ny_neighborhood_stats[ny_neighborhood_stats['Average Rating']>=9.0]
ny_neighborhood_stats
Out[206]:
Neighborhood Average Rating
13 Greenwich Village 9.1
27 Tribeca 9.1
31 West Village 9.0
In [217]:
# join this dataset to original new york data to get lonitude and latitude.

ny_neighborhood_stats=pd.merge(ny_neighborhood_stats,new_york_data, on='Neighborhood')
ny_neighborhood_stats=ny_neighborhood_stats[['Borough','Neighborhood','Latitude','Longitude','Average Rating']]
ny_neighborhood_stats
Out[217]:
Borough Neighborhood Latitude Longitude Average Rating
0 Manhattan Greenwich Village 40.726933 -73.999914 9.1
1 Manhattan Tribeca 40.721522 -74.010683 9.1
2 Manhattan West Village 40.734434 -74.006180 9.0
In [208]:
# visualization on Map

ny_map = folium.Map(location=geo_location('New York'), zoom_start=12)

# instantiate a feature group for the incidents in the dataframe
incidents = folium.map.FeatureGroup()

# loop through the neighborhood and add each to the feature group
for lat, lng, in ny_neighborhood_stats[['Latitude','Longitude']].values:
    incidents.add_child(
        folium.CircleMarker(
            [lat, lng],
            radius=10, # define how big you want the circle markers to be
            color='yellow',
            fill=True,
            fill_color='blue',
            fill_opacity=0.6
        )
    )
    
In [220]:
ny_neighborhood_stats['Label']=ny_neighborhood_stats['Neighborhood']+', '+ny_neighborhood_stats['Borough']+'('+ny_neighborhood_stats['Average Rating'].map(str)+')'
In [221]:
# add pop-up text to each marker on the map
for lat, lng, label in ny_neighborhood_stats[['Latitude','Longitude','Label']].values:
    folium.Marker([lat, lng], popup=label).add_to(ny_map)        
# add incidents to map
ny_map.add_child(incidents)
Out[221]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [211]:
# visualization of Borough

ny_map = folium.Map(location=geo_location('New York'), zoom_start=12)
ny_geo = r'Borough_Boundaries.geojson'

map = ny_map.choropleth(
    geo_data=ny_geo,
    data=ny_borough_stats,
    columns=['Borough', 'Average Rating'],
    key_on='feature.properties.boro_name',
    fill_color='YlOrRd', 
    fill_opacity=0.7, 
    line_opacity=0.2,
    legend_name='Average Rating'
)

# display map
# as this is huge map data , we will save it to a file
ny_map.save('borough_rating.html')

Conclusion:

From our anaysis:

  • Greenwich Village (Manhattan), Tribeca(Manhattan), West Village(Manhattan) are some of the best neighborhoods for Indian cuisine.
  • Manhattan have potential Indian Resturant Market.
  • Bronx ranks last in average rating of Indian Resturants.
  • Manhattan is the best place to stay if you prefer Indian Cuisine.
In [ ]: